import 'package:flutter/material.dart';

// old
abstract class Button {
  Widget buildButton(BuildContext context, String text, VoidCallback onPressed);
}

// new
class CustomButton {
  Widget buildButton(
      BuildContext context, String text, VoidCallback onPressed) {
    return ElevatedButton(onPressed: onPressed, child: Text(text));
  }
}

// adapter
class ButtonAdapter implements Button {
  final CustomButton _customButton;
  ButtonAdapter(this._customButton);
  @override
  Widget buildButton(
      BuildContext context, String text, VoidCallback onPressed) {
    return _customButton.buildButton(context, text, onPressed);
  }
}

class AdapterPatternPage extends StatelessWidget {
  const AdapterPatternPage({
    super.key,
    required this.button,
  });
  final Button button;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: button.buildButton(context, 'Click Me!', () {
          ///
        }),
      ),
    );
  }
}
